package com.yw.start.model;

import java.util.List;

public class ModelManager {
	private List<Model> modelList;

	public List<Model> getModelList() {
		return modelList;
	}

	public void setModelList(List<Model> modelList) {
		this.modelList = modelList;
	}

	public void start() {
		for (Model model : modelList) {
			model.init();
			model.start();
		}
	}

	public void stop() {
		for (Model model : modelList) {
			model.stop();
			model.destroyed();
		}
	}

	public Model getModel(Class<?> c) {
		for (Model model : modelList) {
			if (model.getClass() == c) {
				return model;
			}
		}
		return null;
	}

	public void removeModel(Model model) {
		if (model != null) {
			modelList.remove(model);
			model.stop();
			model.destroyed();
		}
	}

	public void addModel(Model model) {
		modelList.add(model);
		model.init();
		model.start();
	}
}
